﻿#region License
// Copyright © 2004 - 2010 All Right Reserved, Derek Goslin
// 
// 1. Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
// 
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license
//     conditions and limitations in section 3, each contributor grants you a non-exclusive,
//     worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative 
//     works of its contribution, and distribute its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations
//     in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its
//     licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of
//     its contribution in the software or derivative works of the contribution in the software.
// 
// 3. Conditions and Limitations
// (A) Reciprocal Grants- For any file you distribute that contains code from the software (in source code or binary format), 
//     you must provide recipients the source code to that file along with a copy of this license, which license will govern that file. 
//     You may license other files that are entirely your own work and do not contain code from the software under any terms you choose.
// (B) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (C) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
//     your patent license from such contributor to the software ends automatically.
// (D) If you distribute any portion of the software, you must retain all copyright, patent, trademark,
//     and attribution notices that are present in the software.
// (E) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy 
//     of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do 
//     so under a license that complies with this license.
// (F) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions.
//    You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your
//    local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement.
#endregion

using System;
using System.Collections.Generic;
using DnEcuDiag.Ecus.Enums;
using DnEcuDiag.Ecus.Generic;
using DnEcuDiag.Ecus.Kwp;
using DnEcuDiag.Factories;
using NUnit.Framework;

namespace DnEcuDiag.Tests
{
    [TestFixture]
    public class Edc16C9Tests
    {
        private KwpEcu _ecu;
        private KwpTestDevice _device;

        [TestFixtureSetUp]
        public void TestSetup()
        {
            _device = new KwpTestDevice();

            EcuDescriptor descriptor = EcuFactory.EcuList.Find(ecuDescriptor => ecuDescriptor.Name == "Bosch EDC16C9");

            _ecu = EcuFactory.CreateEcu(descriptor) as KwpEcu;
            Assert.IsNotNull(_ecu);
            _ecu.DiagnosticInterface = _device;
            _ecu.Connect();
        }

        [Test]
        public void TestIdentification()
        {
            Assert.AreEqual("Bosch EDC16C9", _ecu.Model);
            Assert.AreEqual("0123456789 ", _ecu.DrawingNumber);
            Assert.AreEqual("0123456789 ", _ecu.HardwareNumber);
            Assert.AreEqual("0x10", _ecu.HardwareVersionNumber);
            Assert.AreEqual("0123456789 ", _ecu.SoftwareNumber);
            Assert.AreEqual("0x85170", _ecu.SoftwareVersionNumber);
            Assert.AreEqual("01234 ", _ecu.OmologationNumber);
            Assert.AreEqual("55 AA 55 AA 55 ", _ecu.IsoCode);
            Assert.AreEqual("19 97 03 31 ", _ecu.ProductionDate);
            Assert.AreEqual("19 97 03 31 ", _ecu.ProgrammingDate);
            Assert.IsNotNull(_ecu.RpmSensor);
            Assert.AreEqual("Engine Speed", _ecu.RpmSensor.Name);
            Assert.IsNotNull(_ecu.SpeedSensor);
            Assert.AreEqual("Vehicle Speed", _ecu.SpeedSensor.Name);
            Assert.AreEqual(InitType.Standard, _ecu.InitType);
        }

        [Test]
        public void TestFaults()
        {
            Assert.AreNotEqual(0, _ecu.ErrorMemoryStructureDefinition.ErrorDefinitions.Count, "_ecu.ErrorMemoryStructureDefinition.Count == 0 for ECU");

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Three P0045
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////			
            _device.FaultcodeList = new byte[] { 0x58, 03, 00, 0x45, 0xE2, 00, 0x45, 0xE2, 00, 0x45, 0xE2 };
            _device.Faultcodeinfo = new byte[12] { 0x57, 0x01, 0x00, 0x45, 0xE2, 0x1D, 0x0D, 0x55, 0xFF, 0xA, 0xFF, 0x40 };
            _ecu.ReadFaultCodes();

            Console.WriteLine(_ecu.ActiveFaultCodes[0].FaultComponent);
            Console.WriteLine(_ecu.ActiveFaultCodes[0].FaultDescription);

            // Test collection.
            Assert.AreEqual(3, _ecu.ActiveFaultCodes.Count, "_ecu.ActiveFaultCodes.Count == 3 for  ECU");

            // Test first fault code.
            Assert.AreEqual("P0045", _ecu.ActiveFaultCodes[0].FaultComponent);
            Assert.AreEqual(String.Format("Failed Component Code: Boost pressure actuator No Load/Excessive Temperature\r\n"
                                          + "Fault Symptom: Short Circuit Gnd/Open Circuit\r\n"
                                          + "Warning Lamp Status: Warning Lamp Illuminated\r\n"
                                          + "Fault Code Storage State: Error Present at time of request\r\n"
                                          + "Event Count: {0} count\r\n"
                                          + "Environmental Condition One: Engine Speed: {1} rpm\r\n"
                                          + "Environmental Condition Two: Fuel Quantity: {2} mm3/str\r\n"
                                          + "Environmental Condition Three: Accelerator Pedal: {3} %\r\n"
                                          + "Environmental Condition Four: Rail Pressure: {4} Bar\r\n"
                                          + "Environmental Condition Five: Turbo Pressure: {5} mBar\r\n"
                                          + "Environmental Condition Six: Engine Temperature: {6} °C\r\n"
                                          , 64, 682.37f, 4.08f, 33.33f, 1999.97f, 117.65f, 127f),
                            _ecu.ActiveFaultCodes[0].FaultDescription);

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // Three U1600
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////			
            _device.FaultcodeList = new byte[] { 0x58, 0x01, 0xD6, 0x00, 0xE8 };
            _device.Faultcodeinfo = new byte[13] { 0x61, 0x10, 0xD6, 0x00, 0xE4, 0x1D, 0x0D, 0x55, 0xFF, 0xA, 0x0A, 0x40, 0x00 };
            _ecu.ReadFaultCodes();

            Console.WriteLine(_ecu.ActiveFaultCodes[0].FaultComponent);
            Console.WriteLine(_ecu.ActiveFaultCodes[0].FaultDescription);

            // Test collection.
            Assert.AreEqual(1, _ecu.ActiveFaultCodes.Count, "_ecu.ActiveFaultCodes.Count == 1 for ECU");

            // Test first fault code.
            Assert.AreEqual("U1600", _ecu.ActiveFaultCodes[0].FaultComponent);
            Assert.AreEqual(String.Format("Failed Component Code: Immobiliser\r\n"
                                          + "Fault Symptom: Wrong key\r\n"
                                          + "Warning Lamp Status: Warning Lamp Illuminated\r\n"
                                          + "Fault Code Storage State: Error Present at time of request\r\n"
                                          + "Event Count: {0} count\r\n"
                                          + "Environmental Condition One: Immobiliser: No Code Received\r\n"
                                          + "Environmental Condition One: Immobiliser: Known Code\r\n"
                                          + "Environmental Condition One: Immobiliser: Erroneous Key Code/Anntena Defect\r\n"
                                          + "Environmental Condition One: Immobiliser: Virgin Ecu\r\n"
                                          + "Environmental Condition One: Immobiliser: Engine Start Disabled\r\n"
                                          + "Environmental Condition One: Immobiliser: Universal Code Received\r\n"
                                          + "Environmental Condition Two: Fuel Quantity: {1} mm3/str\r\n"
                                          + "Environmental Condition Three: Accelerator Pedal: {2} %\r\n"
                                          + "Environmental Condition Four: Rail Pressure: {3} Bar\r\n"
                                          + "Environmental Condition Five: Turbo Pressure: {4} mBar\r\n"
                                          + "Environmental Condition Six: Engine Temperature: {5} °C\r\n"
                                          , 64, 4.08f, 33.33f, 1999.97f, 117.65f, -33.45f),
                            _ecu.ActiveFaultCodes[0].FaultDescription);
        }

        [Test]
        public void TestSensor()
        {
            
            TestSensorValues();
        }

        [Test]
        public void TestSnapshots()
        {
            Int32 i = 0;

            String matchString = String.Empty;
            Byte[] data = null;

            matchString = "Immobiliser\r\n\r\n\tImmobiliser Status\r\n\t\tNo Code Received: True\r\n\t\tCode Unknown: False\r\n\t\t" +
                          "Erroneous Key Code/Anntena Defect: True\r\n\t\tVirgin Ecu: False\r\n\t\tEngine Start Disabled: True\r\n\t\tUniversal Code Received: False\r\n\r\n";
            data = new byte[] { 0x55 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Immobiliser\r\n\r\n\tImmobiliser Status\r\n\t\tNo Code Received: False\r\n\t\tCode Unknown: True\r\n\t\t" +
                          "Erroneous Key Code/Anntena Defect: False\r\n\t\tVirgin Ecu: True\r\n\t\tEngine Start Disabled: False\r\n\t\tUniversal Code Received: True\r\n\r\n";
            data = new byte[] { 0xAA };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Fuel Filter Heater\r\n\r\n\tState\r\n\t\tFuel temperature insufficent to activate heater: True\r\n\t\t" +
                          "Fuel temperature in error, using TH2O: False\r\n\t\tEngine speed (rpm) above threshold to activate heater: True\r\n\t\t" +
                          "Battery voltage above maximum limit: False\r\n\r\n";
            data = new byte[] { 0x55 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Fuel Filter Heater\r\n\r\n\tState\r\n\t\tFuel temperature insufficent to activate heater: False\r\n\t\t" +
                          "Fuel temperature in error, using TH2O: True\r\n\t\tEngine speed (rpm) above threshold to activate heater: False\r\n\t\t" +
                          "Battery voltage above maximum limit: True\r\n\r\n";
            data = new byte[] { 0xAA };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Injection Actuators\r\n\r\n\tState\r\n\t\tPost injection 1 (Poi1) active: True\r\n\t\t" +
                          "Post injection 2 (Poi2) active: False\r\n\t\tPrinciple injection (MI1) active: True\r\n\t\t" +
                          "Pilot injection 1 (Pil1) active: True\r\n\t\tPilot injection 2 (Pil2) active: False\r\n\t\t" +
                          "Pilot injection 3 (Pil3) active: True\r\n\r\n";
            data = new byte[] { 0x55 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Injection Actuators\r\n\r\n\tState\r\n\t\tPost injection 1 (Poi1) active: False\r\n\t\t" +
                          "Post injection 2 (Poi2) active: True\r\n\t\tPrinciple injection (MI1) active: False\r\n\t\t" +
                          "Pilot injection 1 (Pil1) active: False\r\n\t\tPilot injection 2 (Pil2) active: True\r\n\t\t" +
                          "Pilot injection 3 (Pil3) active: False\r\n\r\n";
            data = new byte[] { 0xAA };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Syncronisation Status\r\n\r\n\t\tStage: Initalisation (Power On)\r\n\r\n";
            data = new byte[] { 0x00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Syncronisation Status\r\n\r\n\t\tStage: Counters Reset\r\n\r\n";
            data = new byte[] { 0x01 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Syncronisation Status\r\n\r\n\t\tStage: Timeout. Phase and Revolution signals not received\r\n\r\n";
            data = new byte[] { 0x02 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Syncronisation Status\r\n\r\n\t\tStage: Waiting for Revolution signal\r\n\r\n";
            data = new byte[] { 0x04 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Syncronisation Status\r\n\r\n\t\tStage: Synchronising Phase signal\r\n\r\n";
            data = new byte[] { 33 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Syncronisation Status\r\n\r\n\t\tStage: Defective Phase sensor\r\n\r\n";
            data = new byte[] { 34 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Syncronisation Status\r\n\r\n\t\tStage: Engine synchronized\r\n\r\n";
            data = new byte[] { 48 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "MIL System Status\r\n\r\n\t\tStatus: Activation On request from diagnosis ccm\r\n\r\n";
            data = new byte[] { 1 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "MIL System Status\r\n\r\n\t\tStatus: Activation Blink request from diagnosis ccm\r\n\r\n";
            data = new byte[] { 2 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "MIL System Status\r\n\r\n\t\tStatus: Activation On request from service IOLI\r\n\r\n";
            data = new byte[] { 4 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "MIL System Status\r\n\r\n\t\tStatus: Activation Blink request from service IOLI\r\n\r\n";
            data = new byte[] { 8 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "MIL System Status\r\n\r\n\t\tStatus: Light activated from the check test from Key-On done\r\n\r\n";
            data = new byte[] { 16 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "MIL System Status\r\n\r\n\t\tStatus: Light activated by formal procedure permanent On\r\n\r\n";
            data = new byte[] { 64 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "MIL System Status\r\n\r\n\t\tStatus: Light activated formal procedure Blink\r\n\r\n";
            data = new byte[] { 128 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Neutral state (No adjustment required)\r\n\r\n";
            data = new byte[] { 0x01, 00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Off (Cruise control InActive)\r\n\r\n";
            data = new byte[] { 0x03, 00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Activated regulation down (Set- enabled)\r\n\r\n";
            data = new byte[] { 0x04, 00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Cruise Control activating deceleration\r\n\r\n";
            data = new byte[] { 0x05, 00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Re-enable Cruise Control for higher speed\r\n\r\n";
            data = new byte[] { 0x06, 00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Re-enable Cruise Control for lower speed\r\n\r\n";
            data = new byte[] { 0x07, 00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Activated regulation up (Set+ enabled)\r\n\r\n";
            data = new byte[] { 0x08, 00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Cruise Control activating acceleration\r\n\r\n";
            data = new byte[] { 0x09, 00 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Status\r\n\r\n\t\tStatus: Cruise Control regulated awaiting further commands\r\n\r\n";
            data = new byte[] { 0x0A, 00 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Errors Cruise Control 1\r\n\r\n\t\tCruise control command sequence not plausible\r\n\t\tBrake switch error" +
                          "\r\n\t\tClutch switch error\r\n\t\tVehicle speed error\r\n\t\tRail pressure error\r\n\r\n";
            data = new byte[] { 0x55, 0x55 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Errors Cruise Control 1\r\n\r\n\t\tGeneral error\r\n\t\tAccelerator pedal error" +
                          "\r\n\t\tRPM sensor error\r\n\t\tTurbo pressure error\r\n\t\tDeceleration to fast\r\n\r\n";
            data = new byte[] { 0xAA, 0xAA };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Errors Cruise Control 2\r\n\r\n\t\tCruise control command sequence not plausible\r\n\t\tGeneral error" +
                          "\r\n\t\tBattery voltage too low\r\n\t\tGeneral error\r\n\t\tClutch switch On\r\n\t\t" +
                          "Vehicle speed outside tolerance\r\n\t\t" +
                          "Engine speed to low\r\n\t\tTorque reduction requested from CAN nodes (ASR,ABS,etc)\r\n\t\t" +
                          "Ratio vehicle speed/target speed above threshold\r\n\t\t" +
                          "Absolute difference too high (true speed above target threshold)\r\n\r\n";

            data = new byte[] { 0x55, 0x55, 0x55 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Errors Cruise Control 2\r\n\r\n\t\tOff (Cruise control not active)\r\n\t\tAcceleration too rapid" +
                          "\r\n\t\tBrake switch On\r\n\t\tSelected gear not plausible\r\n\t\tEngine speed to high\r\n\t\t" +
                          "Ratio vehicle speed/engine speed below threshold\r\n\t\tRatio vehicle speed/Engine speed above threshold\r\n\t\t" +
                          "Absolute difference too high (true speed under target threshold)\r\n\t\tRelative difference between target and real speed too high\r\n\r\n";
            data = new byte[] { 0xAA, 0xAA, 0xAA };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tKey on motor stopped\r\n\r\n";
            data = new byte[] { 0 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tEngine speed > 100rpm, no variation in rail pressure\r\n\r\n";
            data = new byte[] { 1 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tClosed loop not monitoring rail pressure\r\n\r\n";
            data = new byte[] { 2 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tClosed loop monitoring rail pressure\r\n\r\n";
            data = new byte[] { 4 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tEngine Off in open loop\r\n\r\n";
            data = new byte[] { 7 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tOpen loop, waiting to transition to closed loop\r\n\r\n";
            data = new byte[] { 8 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tConditions Ok for low test pressure power-latch\r\n\r\n";
            data = new byte[] { 9 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tConditions Ok for low test pressure.con inj OFF PWL\r\n\r\n";
            data = new byte[] { 10 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Rail Pressure Regulation Status\r\n\r\n\t\tConditions Ok for pressure control test in PWL\r\n\r\n";
            data = new byte[] { 11 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Accelerator Pedal State\r\n\r\n\t\tPedal 1 Ok\r\n\r\n";
            data = new byte[] { 16 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Accelerator Pedal State\r\n\r\n\t\tSignal from pedal 1 wrong, using siganl from pedal 2\r\n\r\n";
            data = new byte[] { 17 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Accelerator Pedal State\r\n\r\n\t\tSignal from pedal 2 wrong\r\n\r\n";
            data = new byte[] { 18 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Accelerator Pedal State\r\n\r\n\t\tImplausible signal from pedal 1-2 using the smaller value\r\n\r\n";
            data = new byte[] { 19 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Accelerator Pedal State\r\n\r\n\t\tPedal 1-2 error, using minimum value\r\n\r\n";
            data = new byte[] { 32 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tAir Control Active\r\n\r\n";
            data = new byte[] { 0 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tCut Off, Air Control inhibited\r\n\r\n";
            data = new byte[] { 2 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tStatus Cut-Off during regeneration filtering, Control Off\r\n\r\n";
            data = new byte[] { 3 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tGear Change, Air Control Off\r\n\r\n";
            data = new byte[] { 4 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tEnabled exhaust gas regeneration treatment\r\n\r\n";
            data = new byte[] { 5 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tProlonged Minimum, Air Control Off\r\n\r\n";
            data = new byte[] { 6 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tSystem error, Air Control Off\r\n\r\n";
            data = new byte[] { 8 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tAir value outside tolerance, Air Control Off\r\n\r\n";
            data = new byte[] { 10 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tAtmospheric pressure too low, Air Control Off\r\n\r\n";
            data = new byte[] { 12 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tWater temperature too low, Air Control Off\r\n\r\n";
            data = new byte[] { 14 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tWater temperature too high, Air Control Off\r\n\r\n";
            data = new byte[] { 16 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tBattery voltage to low, Air Control Off\r\n\r\n";
            data = new byte[] { 18 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tQuantity injected too high, Air Control Off\r\n\r\n";
            data = new byte[] { 20 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tCold Start, Air Control Off\r\n\r\n";
            data = new byte[] { 22 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tAir control inhibit request from CCM\r\n\r\n";
            data = new byte[] { 24 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Air Control(ERG)\r\n\r\n\t\tKey in position Off, Air Control Off\r\n\r\n";
            data = new byte[] { 26 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Power Latch State\r\n\r\n\t\tPower-latch not active, Key in position ON\r\n\r\n";
            data = new byte[] { 0 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Power Latch State\r\n\r\n\t\tExecuting engine power latch\r\n\r\n";
            data = new byte[] { 48 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Inhibited Turbo Pressure Regulation\r\n\r\n\t\tTurbo Control Active\r\n\r\n";
            data = new byte[] { 0 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Turbo Pressure Regulation\r\n\r\n\t\tTurbo Control Off, Default value 75%\r\n\r\n";
            data = new byte[] { 6 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Turbo Pressure Regulation\r\n\r\n\t\tTurbo Control Off, Default value 40%\r\n\r\n";
            data = new byte[] { 12 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Inhibited Turbo Pressure Regulation\r\n\r\n\t\tTurbo Control Off, Default value 30%\r\n\r\n";
            data = new byte[] { 18 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Cruise Control Type\r\n\r\n\t\tCruise absent\r\n\r\n";
            data = new byte[] { 0 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Type\r\n\r\n\t\tNon adaptive cruise present\r\n\r\n";
            data = new byte[] { 1 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Type\r\n\r\n\t\tCruise absent\r\n\t\tAdaptive cruise present\r\n\r\n";
            data = new byte[] { 2 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Air Conditioner Type\r\n\r\n\t\tAir Conditioner absent\r\n\r\n";
            data = new byte[] { 0 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Air Conditioner Type\r\n\r\n\t\tAir Conditioner present\r\n\r\n";
            data = new byte[] { 1 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Fan Control\r\n\r\n\t\tWaiting to recognise fan type\r\n\r\n";
            data = new byte[] { 0 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Fan Control\r\n\r\n\t\tPWM controlled Fan\r\n\r\n";
            data = new byte[] { 1 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Fan Control\r\n\r\n\t\t2 fans with 2 digital commands via CCM\r\n\r\n";
            data = new byte[] { 2 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Fan Control\r\n\r\n\t\t1 fan PWM controlled 1 fan digital control\r\n\r\n";
            data = new byte[] { 3 };
            AssertSnapshot(_ecu, i++, data, matchString);

            matchString = "Cruise Control Switch\r\n\r\n\t\tCruise control ON\r\n\t\t" +
                          "Switch resume OFF\r\n\t\t" +
                          "Switch SET - ON\r\n\t\t" +
                          "Switch SET + OFF\r\n\r\n";
            data = new byte[] { 0x55 };
            AssertSnapshot(_ecu, i, data, matchString);

            matchString = "Cruise Control Switch\r\n\r\n\t\tCruise control OFF\r\n\t\t" +
                          "Switch resume ON\r\n\t\t" +
                          "Switch SET - OFF\r\n\t\t" +
                          "Switch SET + ON\r\n\r\n";

            data = new byte[] { 0xAA };
            AssertSnapshot(_ecu, i, data, matchString);
        }

        private void TestSensorValues()
        {
            int i = 0;
            TimeStampedMeasurement tsm;
            var li = _ecu.Sensors[i] as LocalIdentifier;

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 01 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x2 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x4 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x8 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x20 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x0A };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x80 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(128, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(100, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(400, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(10, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(10, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(0.121999994f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(0.099999994f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(0.099999994f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(10, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(10, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(0.099999994f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(10, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0xa, 0xff };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(8.35998917f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0xa, 0xff };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(8.35998917f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0xa, 0xff };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(8.35998917f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0xa, 0xff };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(8.35998917f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(0.099999994f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1.95499992f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(488.76001f, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 10 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(10, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Voltage Above Max.", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Voltage Ok", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 2 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Voltage Below Min.", tsm.Status);
            Assert.AreEqual(2, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Voltage Above Max.", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Voltage Ok", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 2 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Voltage Below Min.", tsm.Status);
            Assert.AreEqual(2, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Request On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Request Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressure Reached", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressure Not Reached", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressure Reached", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressure Not Reached", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x3, 0xE8 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(2, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("True", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("False", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            for (int z = 0; z < 5; z++)
            {
                li = _ecu.Sensors[i] as LocalIdentifier;
                Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));

                byte[] bytes = BitConverter.GetBytes(-32768);
                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, bytes[1], bytes[0] };
                tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
                Assert.AreEqual(-767.940063f, tsm.Measurement);


                bytes = BitConverter.GetBytes(32767);
                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, bytes[1], bytes[0] };
                tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
                Assert.AreEqual(767.916626f, tsm.Measurement);
                i++;
            }

            for (int z = 0; z < 5; z++)
            {
                li = _ecu.Sensors[i] as LocalIdentifier;
                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 1 };

                Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
                tsm = _ecu.ReadSensor(li);

                Assert.AreEqual(1.0f, tsm.Measurement);

                i++;
            }

            for (int z = 0; z < 5; z++)
            {
                li = _ecu.Sensors[i] as LocalIdentifier;
                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

                Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
                tsm = _ecu.ReadSensor(li);

                Assert.AreEqual(1.0f, tsm.Measurement);

                i++;
            }

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressed", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Not Pressed", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressed", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Not Pressed", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Pressed", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Not Pressed", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Oil Pressure OK", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Oil Pressure NOK", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("On", tsm.Status);
            Assert.AreEqual(1, tsm.Measurement);

            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
            Assert.AreEqual("Off", tsm.Status);
            Assert.AreEqual(0, tsm.Measurement);

            i++;

            li = _ecu.Sensors[i] as LocalIdentifier;
            _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 100 };

            Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
            tsm = _ecu.ReadSensor(_ecu.Sensors[i]);

            Assert.AreEqual(1, tsm.Measurement);

            i++;

            for (int z = 0; z < 5; z++)
            {
                li = _ecu.Sensors[i] as LocalIdentifier;
                Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));

                byte[] bytes = BitConverter.GetBytes(-32768);
                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, bytes[1], bytes[0] };
                tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
                Assert.AreEqual(-327.679993f, tsm.Measurement);


                bytes = BitConverter.GetBytes(32767);
                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, bytes[1], bytes[0] };
                tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
                Assert.AreEqual(327.669983f, tsm.Measurement);
                i++;
            }

            for (int z = 0; z < 4; z++)
            {
                li = _ecu.Sensors[i] as LocalIdentifier;
                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x0, 0x1 };

                Console.WriteLine(string.Format("Testing Sensor : {0}", _ecu.Sensors[i].Name));
                tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
                Assert.AreEqual("Switch On", tsm.Status);
                Assert.AreEqual(1, tsm.Measurement);

                _device.LocalidentifierData = new byte[] { 0x61, (Byte)li.Id, 0x00, 00 };

                tsm = _ecu.ReadSensor(_ecu.Sensors[i]);
                Assert.AreEqual("Switch Off", tsm.Status);
                Assert.AreEqual(0, tsm.Measurement);
                i++;
            }
        }

        private void AssertSnapshot(Ecu ecu, Int32 index, IEnumerable<byte> data, String matchString)
        {
            SnapshotDefinition snapshot = ecu.SnapshotDefinitions[index];
            var dataBytes = new List<byte>(new byte[] { 0x61, snapshot.Identifier });
            dataBytes.AddRange(data);

            _device.LocalidentifierData = dataBytes.ToArray();

            String snapshotResult = ecu.ReadSnapshot(snapshot);

            Console.WriteLine(snapshotResult);

            Assert.AreEqual(matchString, snapshotResult);
        }
    }
}
